//
//  LGCarePlanReviewCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/9/18.
//  照护计划 -- 复诊复查

#import "LGCarePlanReviewCell.h"

@interface LGCarePlanReviewCell()
/**   */
@property (nonatomic , strong)UIView *maskView;
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *typeLabel;
/**  待确认标识 */
@property (nonatomic , strong)UILabel *sureTipLabel;
/**   */
@property (nonatomic , strong)UIButton *actionBtn;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UIView *contentView1;
/**   */
@property (nonatomic , strong)UIButton *titleBtn1;
/**   */
@property (nonatomic , strong)UIImageView *finishIcon1;
/**   */
@property (nonatomic , strong)UILabel *contentLabel1;
/**   */
@property (nonatomic , strong)UIView *contentView2;
/**   */
@property (nonatomic , strong)UIButton *titleBtn2;
/**   */
@property (nonatomic , strong)UIImageView *finishIcon2;
/**   */
@property (nonatomic , strong)UILabel *contentLabel2;

@end

@implementation LGCarePlanReviewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.dateLabel.text = LGNSString(dataDic[@"task_date"]);
    //1排队中 3未完成 4已完成
    NSString *status = LGNSString(dataDic[@"task_status_admin"]);
    if([status isEqualToString:@"4"]){
        //已完成
//        self.maskView.hidden = NO;
        self.actionBtn.titleLabel.font = LGFont(15);
        [self.actionBtn setTitleColor:[UIColor colorWithString:@"#666666"] forState:UIControlStateNormal];
        [self.actionBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    }else{
//        self.maskView.hidden = YES;
        self.actionBtn.titleLabel.font = LGFontWeight(15, UIFontWeightMedium);
        [self.actionBtn setTitleColor:[UIColor colorWithString:@"#3291FF"] forState:UIControlStateNormal];
        [self.actionBtn setImage:[UIImage imageNamed:@"grayTip12"] forState:UIControlStateNormal];
    }
    [self.actionBtn setTitle:LGNSString(dataDic[@"task_status_admin_name"]) forState:UIControlStateNormal];
    [self.actionBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:2];
    
    NSString *confirm = LGNSString(dataDic[@"task_status_confirm"]);
    NSString *backColor = [confirm isEqualToString:@"0"]?@"#F1F8FF":@"#FFFFFF";
    NSString *boaderColor = [confirm isEqualToString:@"0"]?@"#4C87FD":@"";
    self.baseView.backgroundColor = [UIColor colorWithString:backColor];
    self.baseView.layer.borderColor = [UIColor colorWithString:boaderColor].CGColor;
    NSString *tipTextColor = [confirm isEqualToString:@"0"]?@"#E3516B":@"#4C87FD";
    NSString *tipBackColor = [confirm isEqualToString:@"0"]?@"#FFDAE0":@"#DFEEFF";
    self.sureTipLabel.textColor = [UIColor colorWithString:tipTextColor];
    self.sureTipLabel.backgroundColor = [UIColor colorWithString:tipBackColor];
    NSString *tips = LGNSString(dataDic[@"tips"]);
    self.sureTipLabel.text = tips;
    CGFloat width = (tips.length>0)?[tips textWidthWithFont:LGFontWeight(12, UIFontWeightMedium) maxHeight:MAXFLOAT]+viewPix(24):0;
    [self.sureTipLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width));
    }];
    
    //检查
    NSString *checkStatus = LGNSString(dataDic[@"task_status_check"]);
    self.finishIcon1.hidden = [checkStatus isEqualToString:@"0"]?YES:NO;
    NSArray *checkArray = dataDic[@"task_check"];
    NSString *checkContent = @"";
    for (NSString *content in checkArray) {
        checkContent = (checkContent.length>0)?[NSString stringWithFormat:@"%@\n%@",checkContent,content]:content;
    }
    self.contentLabel1.text = checkContent;
    [self.contentLabel1 lineSpacing:5];
    self.contentView1.hidden = (checkArray.count>0)?NO:YES;
    CGFloat checkHeight = (checkArray.count == 0)?0:[checkContent textHeightWithFont:LGFont(15) maxWidth:Screen_W-viewPix(80) lineSpacing:5]+viewPix(53);
    [self.contentView1 mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(checkHeight));
    }];
    
    //评估
    NSString *evaStatus = LGNSString(dataDic[@"task_status_evas"]);
    self.finishIcon2.hidden = [evaStatus isEqualToString:@"0"]?YES:NO;
    NSArray *evaArray = dataDic[@"task_eva"];
    NSString *evaContent = @"";
    for (NSString *content in evaArray) {
        evaContent = (evaContent.length>0)?[NSString stringWithFormat:@"%@\n%@",evaContent,content]:content;
    }
    
    self.contentLabel2.text = evaContent;
    [self.contentLabel2 lineSpacing:5];
    self.contentView2.hidden = (evaArray.count>0)?NO:YES;
    CGFloat evaTop = (evaArray.count>0)?viewPix(12):0;
    CGFloat evaBottom = (evaArray.count>0)?-viewPix(12):0;
    CGFloat evaHeight = (evaArray.count == 0)?0:[evaContent textHeightWithFont:LGFont(15) maxWidth:Screen_W-viewPix(80) lineSpacing:5]+viewPix(53);
    [self.contentView2 mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView1.mas_bottom).offset(evaTop);
        make.bottom.equalTo(self.baseView).offset(evaBottom);
        make.height.equalTo(@(evaHeight));
    }];
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
//    [self.contentView addSubview:self.maskView];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.typeLabel];
    [self.baseView addSubview:self.sureTipLabel];
    [self.baseView addSubview:self.actionBtn];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.contentView1];
    [self.baseView addSubview:self.contentView2];
    [self.contentView1 addSubview:self.titleBtn1];
    [self.contentView1 addSubview:self.finishIcon1];
    [self.contentView1 addSubview:self.contentLabel1];
    [self.contentView2 addSubview:self.titleBtn2];
    [self.contentView2 addSubview:self.finishIcon2];
    [self.contentView2 addSubview:self.contentLabel2];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
    }];
//    [self.maskView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.bottom.right.equalTo(self.baseView);
//    }];
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.iconView);
    }];
    [self.sureTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.typeLabel.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.typeLabel);
        make.height.equalTo(@(viewPix(18)));
        make.width.equalTo(@(0));
    }];
    [self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.typeLabel);
        make.width.equalTo(@(viewPix(65)));
        make.height.equalTo(@(viewPix(25)));
    }];
    [self.contentView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(86));
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.height.equalTo(@(viewPix(40)));
    }];
    [self.contentLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView1).offset(viewPix(40));
        make.left.equalTo(self.contentView1).offset(viewPix(12));
        make.right.equalTo(self.contentView1).offset(-viewPix(12));
        make.bottom.equalTo(self.contentView1).offset(-viewPix(12));
    }];
    [self.contentView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView1.mas_bottom).offset(viewPix(12));
        make.bottom.equalTo(self.baseView).offset(-viewPix(12));
        make.left.right.equalTo(self.contentView1);
        make.height.equalTo(@(0));
    }];
    [self.contentLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView2).offset(viewPix(40));
        make.left.equalTo(self.contentView2).offset(viewPix(12));
        make.right.equalTo(self.contentView2).offset(-viewPix(12));
        make.bottom.equalTo(self.contentView2).offset(-viewPix(12));
    }];
}
-(UIView *)maskView{
    if(!_maskView){
        _maskView = [[UIView alloc] init];
        _maskView.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0.15];
        _maskView.cornerRidus = 15;
    }
    return _maskView;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"照护计划-复诊复查"]];
        _iconView.frame = CGRectMake(viewPix(12), viewPix(12), viewPix(24), viewPix(24));
    }
    return _iconView;
}

-(UILabel *)typeLabel{
    if(!_typeLabel){
        _typeLabel = [UILabel lableWithText:@"复诊复查" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _typeLabel;
}

-(UILabel *)sureTipLabel{
    if(!_sureTipLabel){
        _sureTipLabel = [UILabel lableWithText:@"" colorString:@"#4C87FD" textFont:LGFontWeight(12, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _sureTipLabel.backgroundColor = [UIColor colorWithString:@"#DFEEFF"];
        _sureTipLabel.cornerRidus = viewPix(9);
    }
    return _sureTipLabel;
}

-(UIButton *)actionBtn{
    if(!_actionBtn){
        _actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _actionBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _actionBtn.userInteractionEnabled = NO;
    }
    return _actionBtn;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
        _dateLabel.frame = CGRectMake(viewPix(12), viewPix(40), Screen_W-viewPix(56), viewPix(21));
    }
    return _dateLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(viewPix(12), viewPix(74), Screen_W-viewPix(56), 0.5)];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E8E8E8"];
    }
    return _lineView;
}

-(UIView *)contentView1{
    if(!_contentView1){
        _contentView1 = [[UIView alloc] init];
        _contentView1.backgroundColor = [UIColor colorWithString:@"#FAFBFD"];
        _contentView1.cornerRidus = 10;
    }
    return _contentView1;
}

-(UIButton *)titleBtn1{
    if(!_titleBtn1){
        _titleBtn1 = [UIButton buttonWithTitle:@"检查" titleFont:LGFont(16) textColor:@"#333333" imageName:@"照护计划-检查"];
        _titleBtn1.frame = CGRectMake(viewPix(12), viewPix(10), viewPix(150), viewPix(23));
        _titleBtn1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _titleBtn1.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    }
    return _titleBtn1;
}

-(UIImageView *)finishIcon1{
    if(!_finishIcon1){
        _finishIcon1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"照护计划-检查完成"]];
        _finishIcon1.frame = CGRectMake(Screen_W-viewPix(56)-viewPix(36), viewPix(10), viewPix(24), viewPix(24));
        _finishIcon1.hidden = YES;
    }
    return _finishIcon1;
}

-(UILabel *)contentLabel1{
    if(!_contentLabel1){
        _contentLabel1 = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _contentLabel1;
}


-(UIView *)contentView2{
    if(!_contentView2){
        _contentView2 = [[UIView alloc] init];
        _contentView2.backgroundColor = [UIColor colorWithString:@"#FAFBFD"];
        _contentView2.cornerRidus = 10;
    }
    return _contentView2;
}

-(UIButton *)titleBtn2{
    if(!_titleBtn2){
        _titleBtn2 = [UIButton buttonWithTitle:@"评估" titleFont:LGFont(16) textColor:@"#333333" imageName:@"照护计划-评估"];
        _titleBtn2.frame = CGRectMake(viewPix(12), viewPix(10), viewPix(150), viewPix(23));
        _titleBtn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _titleBtn2.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    }
    return _titleBtn2;
}

-(UIImageView *)finishIcon2{
    if(!_finishIcon2){
        _finishIcon2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"照护计划-检查完成"]];
        _finishIcon2.frame = CGRectMake(Screen_W-viewPix(56)-viewPix(36), viewPix(10), viewPix(24), viewPix(24));
        _finishIcon2.hidden = YES;
    }
    return _finishIcon2;
}

-(UILabel *)contentLabel2{
    if(!_contentLabel2){
        _contentLabel2 = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _contentLabel2;
}

@end
